﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Collections;
using System.Windows.Navigation;
using System.Windows.Data;

namespace PasswordProvider.View
{
    /// <summary>
    /// SequentialPageViewerPage
    /// </summary>
    public sealed partial class SequentialPageViewerPage : Page
    {
        public SequentialPageViewerPage()
        {
            InitializeComponent();

            DataContextChanged += new DependencyPropertyChangedEventHandler(SequentialPageViewerPage_DataContextChanged);            
        }

        void SequentialPageViewerPage_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (DataContext != null)
            {
                Binding binding = new Binding("NavigationService");
                binding.Source = DataContext;
                binding.Mode = BindingMode.OneWayToSource | BindingMode.OneTime;
                BindingOperations.SetBinding(this, ViewerNavigationServiceProperty, binding);
                ViewerNavigationService = _frame.NavigationService;            
            }            
        }

        public static readonly DependencyProperty ViewerNavigationServiceProperty =
            DependencyProperty.RegisterAttached("ViewerNavigationService", typeof(NavigationService), typeof(SequentialPageViewerPage));

        /// <summary>
        /// Get the navigation service of the Frame contained in this page.
        /// </summary>
        public NavigationService ViewerNavigationService
        {
            get { return GetValue(ViewerNavigationServiceProperty) as NavigationService; }
            set { SetValue(ViewerNavigationServiceProperty, value); }
        }
    }
}
